<script setup lang="ts">
import { ref } from "vue";
import Taro, { useDidShow } from "@tarojs/taro";

import ApiMerchant from "@/api/merchant";
import useMerchant from "@/stores/merchant";
import checkLogin from "@/utils/checkLogin";
import useFetch from "@/hooks/useFetch";

import { TMerchantInfo } from "@/global";

// const store = useMerchant();

// const { run } = useFetch<TMerchantInfo>(
//   ApiMerchant.getAppMerchantApplyDetail,
//   {
//     immediate: false,
//     afterFetch: (res: any) => res.merchant_apply_detail
//   },
//   { hiddenToast: true }
// );

// useDidShow(() => (!store.merchantData) && run());

// 点击事件
const navigate = async () => {
  // await checkLogin();

  Taro.switchTab({ url: "/pages/merchant/index" });

  // let url = "/packageMerchant/pages/settled/index";
  // const { audit_status = 0 } = data.value || {};

  // switch (audit_status) {
  //   case 0: url = "/packageMerchant/pages/settled/index"; break;
  //   case 1: url = "/pages/merchant/index"; break;
  //   case 2: url = "/packageMerchant/pages/settled/result"; break;
  // }

  // if (audit_status == 1) {
  //   Taro.switchTab({ url });
  // } else {
  //   Taro.navigateTo({ url });
  // }
};


let bottomOffset = 70;
let startPosition: [number, number] = [0, 0];
const style = ref(`bottom:${bottomOffset}px`);

// 拖动
const handleTouchStart = (event) => {
  const { clientX, clientY } = event.touches[0];
  startPosition = [clientX, clientY];
};

const handleTouchMove = (event) => {
  const current = event.changedTouches[0];
  const x = current.clientX - startPosition[0];
  const y = current.clientY - startPosition[1];

  style.value = `bottom:${bottomOffset}px; transform: translate(${x}px,${y}px);`;
};

const handleTouchEnd = ({ changedTouches }) => {
  const current = changedTouches[0];
  // const x = current.clientX - startPosition[0];
  const y = current.clientY - startPosition[1];
  bottomOffset = bottomOffset - y;
  style.value = `bottom:${bottomOffset}px;`;
};
</script>

<template>
  <view catchtouchmove="true">
    <view class="fixed right-3 z-10"
          @tap="navigate"
          @touchstart="handleTouchStart"
          @touchmove="handleTouchMove"
          @touchend="handleTouchEnd"
          :style="style"
          catchmove
          catch-move>
      <image src="/static/svg/fixed.svg" class="w-[180px]" mode="widthFix" />
    </view>
  </view>
</template>